import routerApi from '@apis/route'
export default function  createRoute(){
    const route = {
        name: 'layout',
        path: '/',
        //通用母版页
        component: () =>
            import('@views/layout'),
        children: []
    }
    
    return routerApi.buildMenus().then(res=>{
        route.children = createTree(res)
        return route
    })
}
function createTree(node) {
    const data = []
    for(let j=0;j<node.length;j++){
        if(node[j].type==1){
            data.push({
                name: node[j].path,
                path: node[j].path,
                meta: {
                    title: node[j].title,
                    icon: node[j].icon
                },
                component:()=>import(`@light-app/views${node[j].component}`)
            })
        }else if(node[j].type == 0){
            let temp = {
                name: node[j].path,
                path: node[j].path,
                meta:{
                    title: node[j].title,
                    icon: node[j].icon
                },
                children: []
            }
            if(Array.isArray(node[j].children)&&node[j].children.length){
                const result = createTree(node[j].children)
                temp.children =result
            }
            data.push(temp)
        }
    }
    return data
}